<template>
	<view class="liquorCardManage">
		<view class="manageItemBox" v-if="failureTime">
			<view class="manageItem" @click="choiceTime">
				<view class="left">
					<view class="tit">酒卡失效时间</view>
				</view>
				<view class="right">{{failureTime}}小时</view>
				<u-icon name="arrow-right" color="#999999" size="20"></u-icon>
			</view>
			<view class="manageItem" @tap="chooseGiven(0)">
				<view class="left">
					<view class="tit">受赠人设置</view>
				</view>
				<view class="checkBox" :class="{checkBoxEd:givenAll==0}">
					<view class="check"></view>
				</view>
				<view class="right">禁止非好友接受</view>
			</view>
			<view class="manageItem" @tap="chooseGiven(1)">
				<view class="left"></view>
				<view class="checkBox" :class="{checkBoxEd:givenAll==1}">
					<view class="check"></view>
				</view>
				<view class="right">允许非好友接受</view>
			</view>
		</view>
		
		<!-- 天数选择 -->
		<u-select v-model="timeShow" :list="timeList" title="选择酒卡有效期" @confirm="timeOk"></u-select>
	</view>
</template>

<script>
	export default{
		data() {
			return{
				// 酒卡有效期
				days:null,
				// 酒卡失效时间
				failureTime:null,
				newFailureTime:null,
				// 受赠人设置  1所有人可领 0好友可领
				givenAll:null,
				newGivenAll:null,
				
				timeShow:false,
				timeList:[
					{
						value: '24',
						label: '24小时'
					},
					{
						value: '36',
						label: '36小时'
					}
				]
			}
		},
		onLoad: function (option) {
			this.getSetting();
		},
		methods:{
			// 选择天数
			choiceTime(){
				this.timeShow = true;
			},
			timeOk(val){
				this.newFailureTime = val[0].value;
				this.settingGo();
			},
			// 选择受赠人
			chooseGiven(val){
				this.newGivenAll = val;
				this.settingGo();
			},
			// 获取设置
			getSetting(){
				this.apiget('/mall/storage-liquor/get-setting',{}).then(res => {
					if (res.data.status == 200) {
						this.days = res.data.data.effective_days;
						this.failureTime = res.data.data.given_failure_hours;
						this.givenAll = res.data.data.given_all;
						this.newFailureTime = res.data.data.given_failure_hours;
						this.newGivenAll = res.data.data.given_all;
					}
				})
			},
			// 保存设置
			settingGo(){
				var _this = this;
				this.apipost('/mall/storage-liquor/setting', {effective_days:this.days,given_failure_hours:this.newFailureTime,given_all:this.newGivenAll}).then(res => {
					if (res.data.status == 200) {
						_this.getSetting();
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.liquorCardManage{
		min-height: 100%;
		padding-top: 24rpx;
		background: #F8F8FA;
		
		.manageItemBox{
			padding: 0 32rpx;
			background-color: #fff;
			
			.manageItem{
				display: flex;
				align-items: center;
				padding: 28rpx 0;
				box-shadow: inset 0px -0.5px 0px #F5F5F5;
				
				.left{
					flex: 1;
					width: 1px;
					
					.tit{
						font-size: 28rpx;
						line-height: 44rpx;
						color: #333;
					}
					.tips{
						font-size: 24rpx;
						line-height: 40rpx;
						color: #999;
					}
				}
				
				.right{
					margin-right: 24rpx;
					font-size: 28rpx;
					line-height: 44rpx;
					color: #333;
				}
				
				.checkBox{
					width: 24rpx;
					height: 24rpx;
					margin-right: 8rpx;
					border: 2rpx solid rgba(0, 0, 0, 0.4);
					border-radius: 50%;
					
					.check{
						width: 100%;
						height: 100%;
						border: 2rpx solid #fff;
						border-radius: 50%;
					}
				}
				
				.checkBoxEd{
					border: 2rpx solid #FF5238;
					
					.check{
						background-color: #FF5238;
					}
				}
			}
		}
	}
</style>
